home *** CD-ROM | disk | FTP | other *** search
-
- Dos 'n' Don'ts --- Part 11
-
- by Joel Ellis Rea
-
- --------------------------------------
-
- Now you know how the Command/Error
-
- channel got its name. When
-
- information is sent to the drive
-
- through the Command/Error channel, it
-
- is considered to be a disk command.
-
- When information is requested from the
-
- drive through the Command/Error
-
- channel, it is the Disk Drive Error
-
- Status. Thus, a PRINT# 15, where
-
- Logical File Number 15 was OPENed as
-
- the Command/Error channel of a disk
-
- drive, sends a command to the drive,
-
- while INPUT# 15 asks for drive status.
-
-
- As an example, let's write a short
-
- program that asks the user for the
-
- name of a file, then tells the user if
-
- that file exists on the disk or not.
-
- The way we will tell is by asking the
-
- drive to Rename the file to its own
-
- name. If the Rename succeeds, no harm
-
- is done, since the new name equals the
-
- old name! If it does not succeed, we
-
- can find out why not. One possible
-
- error message we might get back is
-
- Error #63, 'FILE NOT FOUND'. Q.E.D.
-
-
- 10 PRINT "[clr]"
- 20 OPEN 15,8,15,"I0":GOSUB 200
- 30 IF ER% > 19 THEN END
- 40 INPUT "FILE NAME"; F$
- 50 PRINT#15, "R0:"; F$; "="; F$
- 60 GOSUB 200
- 70 IF ER% > 29 AND ER% < 40 THEN
- PRINT "BAD FILENAME": GOTO 40
- 80 IF ER% = 62 THEN PRINT F$;
- "IS NOT ON THE DISKETTE!": END
- 90 IF ER% = 63 THEN PRINT F$;
- "IS ON THE DISKETTE!": END
- 100 PRINT "ERROR #";ER%: PRINT ER$:
- END
- 200 INPUT#15, ER%, ER$, ET%, EB%
- 210 IF ER% = 74 THEN PRINT
- "DOOR OPEN OR NO DISKETTE"
- 220 IF ER% > 19 AND ER% < 30 THEN
- PRINT "BAD DISKETTE"
- 230 RETURN
-
-
- This program begins by clearing the
-
- screen, then OPENing the Command/Error
-
- channel and sending an Initialize
-
- command in one step. A subroutine at
-
- line 200 obtains the disk status and
-
- puts the status code in ER%. Then it
-
- checks it against some common errors.
-
- Any error code less than 20 is
-
- considered OK.
-
-
- We then ask the user for a filename
-
- (line 40) then Rename it to itself
-
- (line 50). Again we call the
-
- subroutine (line 60) to determine the
-
- Drive Status. We first check for a
-
- 'SYNTAX ERROR', which could be caused
-
- by a bad file name. Then we check for
-
- a 'FILE NOT FOUND', which would tell
-
- us that the file does not exist on the
-
- diskette. If the command succeeds,
-
- ('FILE EXISTS'), the file is on the
-
- diskette. We notify the user in any
-
- case.
-
-
- For all you one-finger typists (we
-
- all started that way) we have entered
-
- the program above to save you the
-
- trouble. You'll find it on this side
-
- of LOADSTAR named 'DOS EXAMPLE 1'.
-
- Take a good look at it. LIST it. RUN
-
- it. Modify it to do other things. Be
-
- SURE you understand the Command/Error
-
- channel. It is a powerful tool which
-
- you will need to understand when you
-
- start using data files.
-
- ---------- End of Article ------------
-